#!/bin/bash
#功能函数
funcs=`which functions.sh`
if [ "$funcs" != "" ] ;then
    . $funcs
else
    funcs=`dirname $0`/functions.sh
    echo "$PWD"
    echo "funcs=$funcs"
    if [ "$funcs" != "" ] ;then
	. $funcs
    else
	exit
    fi
fi

list_file1=system/etc/all-appfiles
list_file2=/tmp/all-appfiles
out_dir=$1
result=`adb devices | sed "/List/d"`
if [ -z "$result" ]; then
  echoTextRed "请连接usb到手机,并且确保usb调试已经打开!"
  exit
fi
if [ -z "$out_dir" ];then
  out_dir=`question  "指定输出目录,存放从手机中 adb pull 出的文件 ......"  2  $PWD/release_system`
fi
mkdir -pv $out_dir
rm -rf $list_file2
result=`adb pull $list_file1  $list_file2`
if test -f $list_file2; then
  for f in `cat $list_file2`
  do
    echo "adb pull system/$f $out_dir/$f"
    adb pull system/$f $out_dir/$f
  done
else
  echoTextRed "设备中不存在  $list_file1 文件"
  exit
fi
echoTextBlue  "adb pull out 的文件存放在目录: $out_dir"
echoTextBlue  "用以下命令重新合并,生成system镜像"
echoTextGreen "mkimg-merge-release-apps.sh $out_dir/  /path/to/your/android/src/out/xxx/system/"


